package eu.gline.km.client;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import eu.gline.km.jni.enums.bVk;
import eu.gline.km.jni.enums.dwFlags;
import eu.gline.km.protocol.PROTOCOL;

public class ClientAgent {
	
	private String password;
	
	private Socket socket;
	private DataInputStream dis;
	private DataOutputStream dos;
	
	public ClientAgent(String host, int port, String password) {
		this.password = password;
		createClient(host, port);
	}
	
	public ClientAgent(String host, int port) {
		createClient(host, port);
	}
	
	private void createClient(String host, int port) {
		try {
			socket = new Socket(host, port);
			dis = new DataInputStream(socket.getInputStream());
			dos = new DataOutputStream(socket.getOutputStream());
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void keyboardEvent(bVk bvk, dwFlags dwflags) {
		try {
			dos.writeInt(PROTOCOL.Keyboard);
			dos.writeInt(bvk.value());
			dos.writeInt(dwflags.value());
			dos.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public void foregroundWindow(String string) {
		try {
			dos.writeInt(PROTOCOL.SetForegroundWindow);
			dos.writeUTF(string);
			dos.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void mousePos(int x, int y) {
		try {
			dos.writeInt(PROTOCOL.MousePos);
			dos.writeInt(x);
			dos.writeInt(y);
			dos.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
